package org.doxla.oomwatch.springutil;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * A Spring {@link ApplicationContext} for the Oom-Watch module.
 * Enables the Oom-Watch module to run inside your Spring context.
 *  
 * @author danoxlade
 */
public final class OomWatchApplicationContext extends ClassPathXmlApplicationContext implements ApplicationContextAware {

	/**
	 * The xml application context files for the default oom-watch
	 */
	private static final String[] configLocations = {
		"classpath:/spring/oomContext.xml"
	};
	
	/**
	 * The xml application context providing out of the box scheduling
	 */
	private static final String[] configLocationsWithScheduler = {
		"classpath:/spring/oomAutoContext.xml"
	};

	/**
	 * Default contructor to create the Oom-Watch module
	 * 
	 * @throws BeansException
	 */
	public OomWatchApplicationContext() throws BeansException {
		this(false);
	}

	/**
	 * Contructor which can be used to create an 'out of the box'
	 * working Oom-Watch module using the default scheduler.
	 * You will probably want to configure your own scheduler so that
	 * you can made proper use of the Quartz thread pooling.
	 * 
	 * @param requiresSheduler boolean to indicate if you require the default 'out 
	 * of the box' Quartz scheduler solution.
	 */
	public OomWatchApplicationContext(boolean requiresSheduler) {
		super( requiresSheduler? configLocationsWithScheduler : configLocations);
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		setParent(applicationContext);		
	}


}
